package org.smarthings.things.management.rest.resources.properties;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.w3c.dom.Element;

public class XmlAnyElementAdapter extends XmlAdapter<Element[], Element> {

	@Override
	public Element unmarshal(Element[] elements) throws Exception {
		if (elements == null || elements.length == 0) {
			return null;
		}
		if (elements.length == 1) {
			Element element = elements[0];
			if (!"value".equals(element.getNodeName())) {
				throw new IllegalArgumentException("Unexprected resource filed : "
						+ element.getNodeName());
			}
			return element;
		}
		throw new IllegalArgumentException("Unexprected resource fileds : " + elements);
	}

	@Override
	public Element[] marshal(Element element) throws Exception {
		Element[] elements = new Element[]{element} ;
		return elements;
	}

}
